package com.yjd.comm.base.interceptor;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.yjd.comm.util.TxtFileCacheUtil;

public abstract class UrlInterceptor extends HandlerInterceptorAdapter {

	/**
	 * @Title: urlIsNeedValidate
	 * @Description: 判断url是否需要验证
	 * @param @param requestUrl
	 * @param @return 设定文件
	 * @return boolean 返回类型
	 * @throws
	 */
	protected boolean urlIsNeedValidate(String requestUrl) {
		List<String> urlFiles = this.getUrlFiles();
		if (urlFiles != null && !urlFiles.isEmpty()) {
			for (String urlFile : urlFiles) {
				List<String> list = TxtFileCacheUtil.get(urlFile);
				if (list != null) {
					for (String string : list) {
						Pattern pattern = Pattern.compile(string);
						Matcher matcher = pattern.matcher(requestUrl);
						boolean b = matcher.matches();
						if (b) {
							return false;
						}
					}
				}
			}
		}
		return true;
	}

	protected abstract List<String> getUrlFiles();
}
